﻿@using DeliveryPlus.Web.Classes.Enums
@using DeliveryPlus.Web.Classes.Ext
@model IList<DeliveryPlus.Web.DAL.Entities.Order>

@{
    ViewBag.Title = "Список заказов";
    Layout = "../Shared/ControlPanelLayout.cshtml";
}

<table class="table table-bordered table-hover">
    <thead>
        <tr>
            <th>ИД</th>
            <th>Дата</th>
            <th>Статус</th>
            <th>Адрес доставки</th>
            <th>Контактное лицо</th>
            <th>Контактный телефон</th>
            <th>Блюд</th>
            <th>Стоимость</th>
            <th style="width: 150px"></th>
        </tr>
    </thead>
    <tbody>
        @if (Model.Count == 0)
        {
            <tr>
                <td colspan="9">Не найдено заказов</td>
            </tr>
        }
        else
        {
            foreach (var order in Model)
            {
                <tr>
                    <td>@order.Id</td>
                    <td>@order.DateCreated.FormatDateTime()</td>
                    <td>@(((OrderStatus)order.Status).GetEnumMemberName())</td>
                    <td>
                        @order.DeliveryAddress
                    </td>
                    <td>
                        @order.ContactName
                    </td>
                    <td>
                        @order.ContactPhone
                    </td>
                    <td>
                        @order.OrderItems.Count
                    </td>
                    <td>
                        @String.Format("{0:c}",order.OrderItems.Sum(oi => oi.Price*oi.Quantity))
                    </td>
                    <td>
                        <a href="/ControlPanel/ManageOrders/Edit/@order.Id">Редактировать заказ</a>
                    </td>
                </tr>
            }
        }
    </tbody>
</table>